import java.util.HashSet;

/*
160. 相交链表
 */
public class LeeCode160 {

  public static void main(String[] args) {



  }

  public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
    ListNode temp = headA;
    HashSet<ListNode> set = new HashSet<>();
    while (temp != null){
      set.add(temp);
      temp = temp.next;
    }
    temp = headB;
    while (temp != null){
      if (set.contains(temp)){
        return temp;
      }
      temp = temp.next;
    }
    return null;
  }
}

class ListNode {
  int val;
  ListNode next;
  ListNode(int x) {
    val = x;
    next = null;
  }
}
